<%
   selected_section = controller.class::SECTION if defined?(controller.class::SECTION)
   if selected_section==Navigation::SECTION_RESOURCE && !@project && !@resource
     selected_section = Navigation::SECTION_HOME
   end
   @project=@resource unless @project || selected_section==Navigation::SECTION_HOME
   period_param = "period=#{u(params[:period])}" if params[:period]
%>
<div id="container">
  <%= yield :header -%>
  <div id="hd">
    <div id="nav-left">
      <ul>
        <li>
          <a href="<%= ApplicationController.root_context -%>/" class="<%= 'selected' if selected_section==Navigation::SECTION_HOME || selected_section==Navigation::SECTION_RESOURCE -%>"><%= message('layout.dashboards') -%></a>
        </li>
        <%= render 'layouts/menu_projects' -%>
        <li>
          <a href="<%= ApplicationController.root_context -%>/measures/search?qualifiers[]=TRK" class="<%= 'selected' if selected_section==Navigation::SECTION_MEASURES -%>"><%= message('layout.measures') -%></a>
        </li>
        <li>
          <a href="<%= ApplicationController.root_context -%>/issues/index" class="<%= 'selected' if selected_section==Navigation::SECTION_ISSUES -%>"><%= message('issues.page') -%></a>
        </li>
        <li>
          <a href="<%= ApplicationController.root_context -%>/coding_rules" class="<%= 'selected' if selected_section==Navigation::SECTION_CODING_RULES -%>"><%= message('coding_rules.page') -%></a>
        </li>
        <li>
          <a href="<%= ApplicationController.root_context -%>/profiles" class="<%= 'selected' if selected_section==Navigation::SECTION_QUALITY_PROFILES -%>"><%= message('quality_profiles.page') -%></a>
        </li>
        <li>
          <a href="<%= ApplicationController.root_context -%>/quality_gates" class="<%= 'selected' if selected_section==Navigation::SECTION_QUALITY_GATES -%>"><%= message('quality_gates.page') -%></a>
        </li>
      </ul>
    </div>
    <div id="nav">
      <ul>
        <li>
          <input type="text" size="15" name="search" id="searchInput" value="<%= message('search_verb') -%>">
          <img src="<%= ApplicationController.root_context -%>/images/loading-small.gif" id="searchingResources" style="display:none">
        </li>
        <% if logged_in? %>
          <%= render 'layouts/menu_user' -%>
        <% else %>
          <li><a id="login-link" href="<%= ApplicationController.root_context -%>/sessions/new?return_to=<%= u (request.request_uri) -%>"><%= message('layout.login') -%></a></li>
        <% end %>
        <% if is_admin? %>
          <li><a href="<%= ApplicationController.root_context -%>/settings/index" class="<%= 'selected' if selected_section==Navigation::SECTION_CONFIGURATION -%>"><%= message('layout.settings') -%></a></li>
        <% end %>
      </ul>
    </div>
    <div id="searchResourcesResults" class="autocomplete" style="display:none"
         data-results="<%= message('search.results') -%>"
         data-no-results="<%= message('no_results') -%>"></div>
  </div>
  <%= render 'layouts/breadcrumb' if @breadcrumbs || selected_section==Navigation::SECTION_RESOURCE -%>
  <div id="body">
    <% if selected_section && selected_section.show_sidebar && !@hide_sidebar %>
      <div id="sidebar">
        <ul class="sidebar blue-sidebar">
          <% if selected_section==Navigation::SECTION_HOME %>
            <% ActiveDashboard.user_dashboards(current_user, true).each do |active_dashboard| %>
              <li class="<%= 'active' if @dashboard && controller.controller_path=='dashboard' && active_dashboard.dashboard_id==@dashboard.id -%>">
                <a href="<%= ApplicationController.root_context -%>/dashboard/?did=<%= active_dashboard.dashboard_id -%>"><%= h active_dashboard.dashboard.name(true) -%></a>
              </li>
            <% end %>

            <% controller.java_facade.getPages(Navigation::SECTION_HOME.key, nil, nil, nil, nil).each do |page|
              page_url = (page.isController() ? page.getId() : "/plugins/home/#{page.getId()}")
              selected=request.request_uri.include?("/plugins/home/#{page_url}")
            %>
              <li class="<%= 'active' if selected -%>">
                <a href="<%= ApplicationController.root_context -%><%= page_url -%>"><%= h message(page.getId() + '.page', :default => page.getTitle()) -%></a></li>
            <% end %>

            <li class="spacer"></li>
            <li class="sidebar-title"><%= message('sidebar.tools') -%></li>

            <li class="<%= 'active' if controller.controller_path=='dependencies' -%>">
              <a href="<%= ApplicationController.root_context -%>/dependencies/index"><%= message('dependencies.page') -%></a></li>
            <li class="<%= 'active' if request.request_uri.include?('/comparison/index') -%>">
              <a href="<%= ApplicationController.root_context -%>/comparison/index"><%= message('comparison.page') -%></a>
            </li>

          <% elsif selected_section==Navigation::SECTION_RESOURCE %>
            <% ActiveDashboard.user_dashboards(current_user, false).each do |active_dashboard| %>
              <li class="<%= 'active' if @dashboard && controller.controller_path=='dashboard' && active_dashboard.dashboard_id==@dashboard.id -%>">
                <a href="<%= ApplicationController.root_context -%>/dashboard/index/<%= @project.id -%>?did=<%= active_dashboard.dashboard_id -%><%= "&"+period_param if period_param -%>"><%= h active_dashboard.dashboard.name(true) -%></a>
              </li>
            <% end %>

            <% if @snapshot %>
            <li class="spacer"></li>
            <li class="sidebar-title"><%= message('sidebar.tools') -%></li>
            <li class="<%= 'active' if request.request_uri.include?('/components/index') -%>">
              <a href="<%= ApplicationController.root_context -%>/components/index/<%= @project.id -%>"><%= message('components.page') -%></a>
            </li>
            <li class="<%= 'active' if request.request_uri.include?('/drilldown/issues') -%>">
              <a href="<%= ApplicationController.root_context -%>/drilldown/issues/<%= @project.id -%><%= "?"+period_param if period_param -%>"><%= message('issues_drilldown.page') -%></a>
            </li>
              <% project_metrics = @project.last_snapshot.metric_keys.to_java(:string) if @project.last_snapshot
                controller.java_facade.getPages(Navigation::SECTION_RESOURCE.key, @project.scope, @project.qualifier, @project.language, project_metrics).each do |page|
                page_url = (page.isController() ? "#{page.getId()}?id=#{@project.id}" : "/plugins/resource/#{@project.id}?page=#{page.getId()}")
              %>
              <li class="<%= 'active' if request.request_uri.include?(page_url) -%>">
                <a href="<%= ApplicationController.root_context -%><%= page_url -%>"><%= h message(page.getId() + '.page', :default => page.getTitle()) -%></a>
              </li>
              <% end %>
              <% if controller.java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'comparable') %>
              <li class="<%= 'active' if request.request_uri.include?('/comparison/index') -%>">
                <a href="<%= ApplicationController.root_context -%>/comparison/index?resource=<%= @project.key -%>"><%= message('comparison.page') -%></a>
              </li>
              <% end %>
            <% end %>

          <% elsif selected_section==Navigation::SECTION_CONFIGURATION %>

            <% if is_admin? %>

            <li class="sidebar-title"><%= message('sidebar.project_settings') -%></li>
            <li class="<%= 'active' if request.request_uri.include?('/settings') -%>">
              <a href="<%= ApplicationController.root_context -%>/settings/index"><%= message('settings.page') -%></a></li>
            <li class="<%= 'active' if controller.controller_path=='metrics' -%>">
              <a href="<%= ApplicationController.root_context -%>/metrics/index"><%= message('manual_metrics.page') -%></a></li>
            <li class="<%= 'active' if controller.controller_path=='admin_dashboards' -%>">
              <a href="<%= ApplicationController.root_context -%>/admin_dashboards/index"><%= message('default_dashboards.page') -%></a></li>
            <% controller.java_facade.getPages(Navigation::SECTION_CONFIGURATION.key, nil, nil, nil, nil).each do |page|
              page_url = (page.isController() ? page.getId() : "/plugins/configuration/#{page.getId()}")
            %>
              <li class="<%= 'active' if request.request_uri.include?(page_url) -%>">
                <a href="<%= ApplicationController.root_context -%><%= page_url -%>"><%= h message(page.getId() + '.page', :default => page.getTitle()) %></a>
              </li>
            <% end %>
            <li class="spacer"></li>
            <li class="sidebar-title"><%= message('sidebar.security') -%></li>
            <li class="<%= 'active' if request.request_uri.include?('/users') -%>"><a href="<%= ApplicationController.root_context -%>/users"><%= message('users.page') -%></a>
            </li>
            <li class="<%= 'active' if request.request_uri.include?('/groups') -%>">
              <a href="<%= ApplicationController.root_context -%>/groups/index"><%= message('user_groups.page') -%></a></li>
            <li class="<%= 'active' if request.request_uri.include?('/roles/global') -%>">
              <a href="<%= ApplicationController.root_context -%>/roles/global"><%= message('global_permissions.page') -%></a></li>
            <li class="<%= 'active' if request.request_uri.include?('/roles/projects') || request.request_uri.include?('/permission_templates') -%>">
              <a href="<%= ApplicationController.root_context -%>/roles/projects"><%= message('roles.page') -%></a></li>

            <li class="spacer"></li>
            <li class="sidebar-title"><%= message('sidebar.system') -%></li>
            <% if has_role?("provisioning") %>
            <li class="<%= 'active' if controller.controller_path=='provisioning' -%>">
              <a href="<%= ApplicationController.root_context -%>/provisioning"><%= message('provisioning.page') -%></a>
            </li>
            <% end %>
            <li class="<%= 'active' if controller.controller_path=='bulk_deletion' -%>">
              <a href="<%= ApplicationController.root_context -%>/bulk_deletion"><%= message('bulk_deletion.page') -%></a>
            </li>
            <% update_center_activated = controller.java_facade.getSettings().getBoolean('sonar.updatecenter.activate')
               if update_center_activated %>
              <li class="<%= 'active' if controller.controller_path=='updatecenter' -%>">
                <a href="<%= ApplicationController.root_context -%>/updatecenter"><%= message('update_center.page') -%></a></li>
            <% end %>
            <li class="<%= 'active' if controller.controller_path=='system' -%>">
              <a href="<%= ApplicationController.root_context -%>/system"><%= message('system_info.page') -%></a></li>

            <% end #of admin part %>

          <% end %>

          <%= yield :sidebar %>

          <li id="logo">
            <center><a href="http://www.sonarqube.org/" target="SonarSource"><%= image_tag('logo.png', :alt => message('layout.sonar.slogan'), :width => 100, :height => 24) -%></a></center>
          </li>
        </ul>
      </div>
    <% end %>
    <%
      html_id_class = ''
      html_id_class = "id='content' class='with_sidebar'" if selected_section && selected_section.show_sidebar
      html_id_class = "id='content'" if @hide_sidebar || (selected_section && !selected_section.show_sidebar)
    %>
    <div <%= html_id_class -%>>
      <% if @project %>
        <div class="print"><h2><%= h @project.name(true) %></h2></div>
      <% end %>
      <div class="error" id="error" style="display:none">
        <span id="errormsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#error').hide();return false;"><%= message('hide').downcase -%></a>]
      </div>
      <div class="notice" id="info" style="display:none">
        <span id="infomsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#info').hide();return false;"><%= message('hide').downcase -%></a>]
      </div>
      <div class="warning" id="warning" style="display:none">
        <span id="warningmsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#warning').hide();return false;"><%= message('hide').downcase -%></a>]
      </div>
      <%= yield %>
    </div>
  </div>
</div>

<% unless params[:hd]=='false' %>
  <%= yield :footer %>
  <div id="footer">
    <% controller.java_facade.getWebFooters().each do |footer| %>
      <% if footer.getHtml() %>
        <div><%= footer.getHtml().to_s %></div>
      <% end %>
    <% end %>
    <div id="ftlinks">
      <%= render 'branding/footer' -%>
      <div>
        Version <%= sonar_version -%> -
        <a href="http://www.sonarqube.org" target="sonar">Community</a> -
        <a href="http://www.sonarqube.org/documentation" target="sonar_doc">Documentation</a> -
        <a href="http://www.sonarqube.org/support" target="support">Get Support</a> -
        <a href="http://sonar-plugins.codehaus.org" target="plugins">Plugins</a> -
        <a href="<%= ApplicationController.root_context -%>/api_documentation">API</a>
        <% unless DatabaseVersion.production? %>
          <br><br><span class="error big" id="evaluation_warning">Embedded database should be used for evaluation purpose only</span>
          <br><br><span class="error">The embedded database will not scale, it will not support upgrading to newer versions of SonarQube, and there is no support for migrating your data out of it into a different database engine.</span>
        <% end %>
      </div>
      <!--[if lte IE 8 ]><br/><span class="ie-warn">IE 8 is not supported. Some widgets may not be properly displayed. Please switch to a <a target="_blank" href="http://docs.codehaus.org/x/zYHEBg">supported version or another supported browser</a>.</span><!--<![endif]-->
    </div>
  </div>
<% end %>
